<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        $bbsdata=M('think_data');
        $data=$bbsdata->order('id desc')->select();
        $bbscount=$bbsdata->count();
        $this->assign('bbscount',$bbscount);
        $this->assign('rows',$data);
        $this->display();
        
    }
    public function del()
     {
        $id=I('get.id',0);
        $bbsdata=M("think_data");
        $rs=$bbsdata->delete($id);
        if($rs)
        {
           $this->success('删除成功',U('Home/Index/index'));
        }
        else 
        {
            $this->error('删除失败');
        }
    }
    public function edit()
    {
        $id=I('get.id',0);
        $model=M('think_data');
        $r=$model->where("id=$id")->find();
        $this->assign("row",$r);
        $this->display();
    }
        public function update()
        {
            if(IS_POST)
            {
              $id=I('get.id',0);
              $data['username']=I('post.username','');
              $data['sex']=I('post.sex','男');
              $data['message']=I('post.message','');
              $data['imgurl']=I('post.imgurl','');
              $data['m_date']=date('Y-m-d H:i:s',  time());
              $model=M('think_data');
              $model->where("id=$id")->save($data);
              $this->success('修改完成！',U('Home/Index/index'));
            } else {
                $this->error('非法操作！');
            }
            }
        

}